import { defineConfig,ConfigEnv,UserConfig ,loadEnv} from 'vite'
import { createHtmlPlugin } from "vite-plugin-html";
import { resolve } from "path";
import { wrapperEnv } from "./src/utils/getEnv";
import vue from '@vitejs/plugin-vue'



// https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig =>{
  const env = loadEnv(mode, process.cwd());
	const viteEnv = wrapperEnv(env);
  
  return{
		resolve: {
			alias: {
				"@": resolve(__dirname, "./src")
			}
		},
		define: {
			'import.meta.env.VITE_SERVER_URL': process.env.SERVER_URL
		},
    server: {
			host: '127.0.0.1', // 服务器主机名，如果允许外部访问，可设置为"0.0.0.0"
			port: 8080,
			open: true,
			cors: true,
		},
		pure: viteEnv.VITE_DROP_CONSOLE ? ["console.log", "debugger"] : [],
		build: {
			minify: "esbuild",
		},
    plugins: [
			vue(),
      createHtmlPlugin({
				inject: {
					data: {
						title:'网页上传'
					}
				}
			}),
			// * vite 可以使用 jsx/tsx 语法
    ]
  }
})
